<?php

namespace Transaccion\Controller;

use Transaccion\Controller\GenericController;
use Componentes\Controller\UtilsArrayController;
use Transaccion\Model\Entity\DatosAcademicos;

class DatosAcademicosController extends GenericController {

    public function __construct() {
        
    }

    public function get($id) {
        /*
         * Datos del datosAcademicos COMPLETO (con el grupo)
         * Ej: http://localhost/UptaebBackend/public/transaccion/datosAcademicos/07443224
         * Rsp: {"success":true,"data":[{"salumid":"07443224","slapsid":"201421",
         * "sconmtrid":"34","idatacaaprobado":60,"idatacaaplazado":8,
         * "idatacarestante":138,"rdatacaindice":"14.43","sespeid":"05028",
         * "sdatacaturno":"TARDE","idatacatrayecto":"TII","idatacaperiodo":"ANUAL",
         * "rdatacaindgra":"0","rdatacaindlapso":"0","sdatacapriori":"1","estado":"9"}],
         * "total":1,"mensaje":null}
         */
        $id = $this->params()->fromRoute('id');
        $output = $this->getDatosAcademicosService()->getRegistro($id);
        return $this->convertirArrayAJson($output);
    }

    /**
     * Return list of resources
     * @return mixed
     */
    public function getList($id = 1, $param1 = 1, $param2 = 1, $param3 = 1) {
        $id = $this->params()->fromRoute('id');
        $param1 = $this->params()->fromRoute('param1');
        $data = null;
        $mensaje = "Defaul";
        switch ($id) {
            case (0):
                /*
                 * Datos del datosAcademicos sin los objetos foraneos (con el id del grupo)
                 * Ej: http://localhost/UptaebBackend/public/transaccion/datosAcademicos/0/1
                 * Rsp: {"success":true,"data":[{"id":1,"login":"07443224","password":"123","estado":1,"_grupo":{"id":1,"nombre":"Estudiante","detalle":"Estudiantes activos"}}],"total":1}
                 */
                $id = $this->params()->fromRoute('param1');
                $output = $this->getDatosAcademicosService()->getRegistroCompleto($id);
                break;
            case (1):
                /*
                 * Datos del datosAcademicos dado el login
                 * Ej: http://localhost/UptaebBackend/public/transaccion/datosAcademicos/1/15598390
                 * Rsp: {"success":true,"data":[{"id":"1","login":"07443224","password":"123","id_grupo":"1","estado":1}],"total":1,"mensaje":null}
                 */
                $cedula = $this->params()->fromRoute('param1');
                $output = $this->getDatosAcademicosService()->getUltimoDatosAcademicosSegunCedula($cedula);
                break;
            case (2):
                /*
                 * Valida el datosAcademicos
                 * Si el datosAcademicos es valido retorna los datos del grupo a cual pertenece
                 * Ej: http://localhost/UptaebBackend/public/transaccion/datosAcademicos/2/07443224/123
                 * Rsp: {"success":true,"data":[{"id":1,"nombre":"Estudiante","detalle":"Estudiantes activos"}],"total":1,"mensaje":"INICIO DE SESION EXITOSA"}
                 */
//                $login = $this->params()->fromRoute('param1');
//                $password = $this->params()->fromRoute('param2');
//                $output = $this->getDatosAcademicosService()->validarDatosAcademicos($login, $password);
                break;
            case (3):
                Ej: http://localhost/UptaebBackend/public/transaccion/datosAcademicos/3/3
                $id = $this->params()->fromRoute('param1');
                $output = $this->getDatosAcademicosService()->getRegistroCompletoSegunIngresoMalla($id);
                break;
            default:
                return $param1;
        }
        return $this->convertirArrayAJson($output);
    }

    /**
     * Create a new resource
     * @param  mixed $data
     * @return mixed
     * Ruta: http://localhost/UptaebBackend/public/seguridad/bitacora/@idUsuario/@idNodo/@detalle/@otro
     * Ej: http://localhost/UptaebBackend/public/seguridad/bitacora/1/1/Click_boton_de_inicio_de_sesion/null
     */
    public function create($data) {
        $id = $this->params()->fromRoute('id');
        $idIngresoMalla = $this->params()->fromRoute('param1');
        $idLapso = $this->params()->fromRoute('param2');
        $idCondicionMatricular = $this->params()->fromRoute('param3');
        $idTrayectoSemestre = $this->params()->fromRoute('param4');
        $idTurno = $this->params()->fromRoute('param5');
        $idSeccion = $this->params()->fromRoute('param6');
        $idControlInscripcion = $this->params()->fromRoute('param7');
        $result = $this->getDatosAcademicosService()->createRegistro($idIngresoMalla, $idLapso, $idCondicionMatricular, $idTrayectoSemestre, $idTurno, $idSeccion, $idControlInscripcion);
        $response = $this->getResponseWithHeader();
        $response->setContent($result);
        return $response;
    }

    public function delete($id) {
        $id = $this->params()->fromRoute('id');
        $result = $this->getDatosAcademicosService()->deleteDatosAcademicosSegunId($id);
        $response = $this->getResponseWithHeader();
        $response->setContent($result);
        return $response;
    }

}
